Home:ALL Converter>Ubuntu container immediately exits after `docker run ubuntu`

Ubuntu container immediately exits after `docker run ubuntu`

Ask Time:2020-09-02T09:33:51         Author:math4545454

Json Formatter

I am on Windows 10 and I have WSL2 enabled. When I do docker pull ubuntu followed by docker run ubuntu, a new ubuntu container with a randomly generated name shows up in my dashboard and it starts for half a second, but then immediately stops. If I press the start button the same behaviour is observed. I tried running these commands from Command Prompt, PowerShell, and my downloaded Ubuntu 18.04 distro (which is also my default WSL2 distro) all with the same result.

How do I fix this?

Also, docker logs <container_name> doesn't result in anything and double-clicking the container name in the dashboard doesn't show any logs.

Author:math4545454,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/63697495/ubuntu-container-immediately-exits-after-docker-run-ubuntu
Savio Mathew :

A docker container exits when its main process finishes its execution. Now when you check Dockerfile of Ubuntu image you can see the\nCMD ["/bin/bash"] which get execute when we start the container.\nso if you need to run the container in the background you can do\ndocker run -id --name=myubuntu ubuntu \n\nOr you can directly launch the container with an interactive shell using\ndocker run -it --name=myubuntu ubuntu /bin/bash\n",
2020-09-02T06:24:35
yy